package addon.w3.mdx.com;

import java.io.IOException;

import addon.w3.mdx.MDXCOM;
import addon.w3.mdx.LEDataInputStream;
import addon.w3.mdx.MDXException;

/**
	struct {
		OBJ
		long	Shape;			(0:box;2:sphere)
		float 	x, y, z;
		if (Shape == 0)
			float	x2, y2, z2;
		else
			float	BoundsRadius
	} collisionshape[nclds];
 * @author madjk
 *
 */
public class MDXCollisionShapeCOM extends MDXCOM {
	MDXObject obj;
	int shape = -1;
	float pos[];
	float pos2[];
	float boundsRadius = -1;
	
	int size = 0;
		
	public String getTag() {
		return "CLID:collisionShape";
	}
	
	public int getSize() {
		return size;
	}
	
	public void _decode(LEDataInputStream ins) throws IOException, MDXException {
		obj = new MDXObject();
		obj.decode(ins);
		size += obj.nbytesi;
		shape = ins.readInt();
		size += 4;
		pos = new float[3];
		for (int i = 0; i < pos.length; i++) {
			pos[i] = ins.readFloat();
		}
		size += 12;
		if(shape == 0) {
			pos2 = new float[3];
			for (int i = 0; i < pos2.length; i++) {
				pos2[i] = ins.readFloat();
			}
			size += 12;
		} else {
			boundsRadius = ins.readFloat();
			size += 4;
		}
		//debug(this.toString());
	}
	
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("TAG : "+getTag());
		sb.append("\n\tOBJ : "+(obj == null ? false : obj.toString()) );
		sb.append("\n\tSHAPE : "+shape);
		sb.append("\n\tPOS : "+pos[0]+" : "+pos[1]+" : "+pos[2]);
		if(shape == 0) {
			sb.append("\n\tPOS2 : "+pos2[0]+" : "+pos2[1]+" : "+pos[2]);
		} else {
			sb.append("\n\tBOUNDSRADIUS : "+boundsRadius);
		}
		return sb.toString();
	}

	@Override
	public boolean isImplicitTag() {
		// TODO Auto-generated method stub
		return false;
	}
}